#include <stdio.h>
long long A=1992919, B=18181971;
FILE *f=NULL;
char s[20];
int ts=1;
int next()
{
	A=(A*13166771+B)%1000000007;
	B=(B*67771+A)%1000000007;
	return A;
}
void createtest()
{
	if(f!=NULL)
		fclose(f);
	sprintf(s, "%03d", ts);
	ts++;
	f=fopen(s, "w");
}

void gen0()
{
	createtest();
	fprintf(f,"2 7 4\n0\n6\n7\n8\n");
	createtest();
	fprintf(f,"3 7 4\n0\n6\n7\n8\n");
}

void gen(int k,int p,int n)
{
	createtest();
	fprintf(f,"%d %d %d\n",k,p, n);
	while(n--)
		fprintf(f,"%lld\n",(long long)next()*next()%1000000000000000000LL);
}

int main()
{
	gen0();
	gen(2,2,100);
	gen(3,2,1000);
	gen(4,41,10010);
	int i,k,p,j;
	for(i=0;i<10;i++)
	{
		k=next()%1000+1;
		p=next()%1000002+2;
		while(1)
		{
			for(j=2;j*j<=p;j++)
				if(p%j==0)
					break;
			if(j*j>p)
				break;
			p++;
		}
		gen(k,p,100000);
	}
	return 0;
}